import md5 from './md5.min.js';
export default {
  myCommonSalt: function (val) { // 获取盐值
    let len = parseInt(val);
    let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    let maxPos = $chars.length;
    var pwd = '';
    for (var i = 0; i < len; i++) {
      pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    console.log(pwd);
    return pwd;
  },
  getQueryString: function(location) {
    //var url = location.search; //获取url中"?"符后的字串
    console.log(location)
    var url = location.href.split("?")[1];
    var theRequest = new Object();
    if (url) {
      // var str = url.substr(1);
      var strs = url.split("&");
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
      }
    } else {
      theRequest = null;
    }
    return theRequest;
  },

  parseParams: function (data) {
    try {
      var tempArr = [];
      for (var i in data) {
        var key = (i);
        var value = encodeURIComponent(data[i]);//decodeURIComponent
        tempArr.push(key + '=' + value);
      }
      var urlParamsStr = tempArr.join('&');
      return urlParamsStr;
    } catch (err) {
      return '';
    }
  },


  IsWeixinOrAlipay: function () {
    if (/MicroMessenger/.test(window.navigator.userAgent)) {
      console.log("微信客户端");
      //this.switchShow("wxPay");
      return 4
    } else if (/AlipayClient/.test(window.navigator.userAgent)) {
      console.log("支付宝客户端");
      //this.switchShow("aliPay");
      return 1
    } else if (/BankabciPhone/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '34'
    } else if (/BankabcAndroid/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '34'
    } else {
      console.log("其他浏览器");
      return 1
    }
  },



  dateFormat: function (msd) {  // 时间转换
    var time = msd

    if (null != time && "" != time) {

      if (time > 60 && time < 60 * 60) {

        time = parseInt(time / 60.0) + "分钟" + parseInt((parseFloat(time / 60.0) -

          parseInt(time / 60.0)) * 60) + "秒";

      }

      else if (time >= 60 * 60 && time < 60 * 60 * 24) {

        time = parseInt(time / 3600.0) + "小时" + parseInt((parseFloat(time / 3600.0) -

          parseInt(time / 3600.0)) * 60) + "分钟" +

          parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -

            parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";

      } else if (time >= 60 * 60 * 24) {

        time = parseInt(time / 3600.0 / 24) + "天" + parseInt((parseFloat(time / 3600.0 / 24) -

          parseInt(time / 3600.0 / 24)) * 24) + "小时" + parseInt((parseFloat(time / 3600.0) -

          parseInt(time / 3600.0)) * 60) + "分钟" +

          parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -

            parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";

      }

      else {

        time = parseInt(time) + "秒";

      }

    }

    return time;
  },
  formatTime: function (value) {
    let date = new Date(value);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d
  },

  signObject: function (jsonObj){ //签名字段
    let sort = []
    for(let k in jsonObj){
      sort.push({
        keyname: k,
        value: jsonObj[k]
      })
    }
    return this.myGetSign(sort)
  },

  clientBrowser: function () { // 判断客户端
    if (/MicroMessenger/.test(window.navigator.userAgent)) {
      console.log("微信客户端");
      return '微信'
    } else if (/AlipayClient/.test(window.navigator.userAgent)) {
      console.log("支付宝客户端");
      return '支付宝'
    } else if (/BankabciPhone/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '立即'
    }else if (/BankabcAndroid/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '立即'
    }else {
      console.log("其他浏览器");
      return '支付宝'
    }
  },
  // 1:支付宝 2：微信 3：银联 10:H5   4微信公众号
  clientBrowserPayType: function () { // 判断客户端
    if (/MicroMessenger/.test(window.navigator.userAgent)) {
      console.log("微信客户端");
      return '4'
    } else if (/AlipayClient/.test(window.navigator.userAgent)) {
      console.log("支付宝客户端");
      return '1'
    } else if (/BankabciPhone/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '34'
    }else if (/BankabcAndroid/.test(window.navigator.userAgent)) {
      console.log("农行客户端");
      return '34'
    }else {
      console.log("其他浏览器");
      return '1'
    }
  },



  // 0eca8f5373ca4866aec2f8e9d9367104  老的id
  // 14318527b13840c2a4af63fef52c2d6e 老的签名

  // ud8yq5tv0inxupc05xfeau39jywlqoj2  新的id
  // ny1u72b6k374sg379z0kqjgfxe2ycnpw 新的签名

  myVarAppid:'ud8yq5tv0inxupc05xfeau39jywlqoj2',// 公共请求Appid

  myDeviceInfo: 'BC0703A4-AFB0-4B51-9089-9B7487C0CC6E', // 公共请求设备信息

  myVxAppId: 'wx78702b90dadb9586',
  // 西城  wx78702b90dadb9586
  // 测试环境 微信赤峰 appid   wxff4cebaedbf4f886
  // 微信赤峰 appid   wx2af2bab90d433c86


  myOrgId: '10007', // 归属地 赤峰id  10003    黄石 10079   西城10007

  myGetSign: function (objb) { // 获取签名
    var compare = function (obj1, obj2) {
      var val1 = obj1.keyname;
      var val2 = obj2.keyname;
      if (val1 < val2) {
        return -1;
      } else if (val1 > val2) {
        return 1;
      } else {
        return 0;
      }
    }
    objb.sort(compare);
    var strmd5 = 'ny1u72b6k374sg379z0kqjgfxe2ycnpw';
    for(var i=0;i<objb.length;i++){
      if(objb[i].value != null&&objb[i].value != ''){
        strmd5 += objb[i].keyname+objb[i].value;
      }
    }
    strmd5 += 'ny1u72b6k374sg379z0kqjgfxe2ycnpw';
    // console.log('strmd5-------->'+strmd5);
    strmd5 = md5(strmd5);
    strmd5=strmd5.toUpperCase();
    return strmd5;
  },

}
